//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __NEPTUNE_PPP_H__
#define __NEPTUNE_PPP_H__


#define OUT_BUF_NUM   20

/* MAX num of ppp connection
* it must be equal to the value defined in opt.h
*/
#ifndef NUM_PPP
#define NUM_PPP       3
#endif

typedef unsigned short  u16_t;

#ifdef _DEBUG
#define NPPP_LOG1(x)            kprintf(x)
#define NPPP_DUMPBIN(x, y)      dumpBin(x, y)
#else
#define NPPP_LOG1(x)
#define NPPP_DUMPBIN(x, y)
#endif // _DEBUG


struct pbuf
{
    struct pbuf *next;
    void *payload;
    void *limit;
    u16_t tot_len;
    u16_t len;
    u16_t flags;
    u16_t ref;
};

enum pppAuthType
{
    PPPAUTHTYPE_NONE,
    PPPAUTHTYPE_ANY,
    PPPAUTHTYPE_PAP,
    PPPAUTHTYPE_CHAP
};

typedef struct _PPPAuthData
{
    enum pppAuthType authType;
    char user[32];
    char passwd[32];
} PPPAuthData;

typedef struct _PPPAddr
{
    UInt32 our;
    UInt32 host;
    UInt32 mask;
    UInt32 dns1;
    UInt32 dns2;
} PPPAddr;

typedef struct _PPPIoctlData
{
   UInt32 pd;
   UInt32 cmd;
   UInt32 arg;
} PPPIoctlData;

//control code
#define PPP_INIT           100
#define PPP_SETAUTH        200
#define PPP_OPEN           300
#define PPP_CLOSE          400
#define PPP_IOCTOL         500
#define PPP_SETADDR        700
#define PPP_GETADDR        800
#define PPP_GETDNS         801
#define PPP_WAITUP         900
#define PPP_READABORT      901

//
// NeptunePPPTranceiver
//
class NeptunePPPTranceiver : public CDeviceDriver
{

public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();

    friend ECode fnNeptuneReader(PVoid pvData);

public:
    NeptunePPPTranceiver();
    ~NeptunePPPTranceiver();
    CARAPI Init();

public:
    //buffer to read and write
    Boolean  m_bThreadRun;
    IThread *m_pThreadRead;
};

#endif

